You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@types/json-stable-stringify

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/json-stable-stringify

Stub TypeScript definitions entry for json-stable-stringify, which provides its own types definitions

1.2.0
latest
npmnpm
Version published
Maintainers
1
Created

What is @types/json-stable-stringify?

@types/json-stable-stringify is a TypeScript type definition package for the json-stable-stringify library. This library provides a way to stringify JavaScript objects in a consistent and stable order, which is useful for tasks like comparing JSON objects or generating consistent hash values.

What are @types/json-stable-stringify's main functionalities?

Stable Stringification

This feature allows you to stringify a JavaScript object in a stable order. The keys in the resulting JSON string are sorted, ensuring consistent output for the same input object.

{"typescript":"import stringify from 'json-stable-stringify';\n\nconst obj = { b: 1, a: 2 };\nconst stableString = stringify(obj);\nconsole.log(stableString); // Output: '{\"a\":2,\"b\":1}'"}

Custom Comparator

This feature allows you to provide a custom comparator function to control the order of keys in the resulting JSON string. In this example, the keys are sorted in reverse order.

{"typescript":"import stringify from 'json-stable-stringify';\n\nconst obj = { b: 1, a: 2 };\nconst stableString = stringify(obj, { cmp: (a, b) => a.key < b.key ? 1 : -1 });\nconsole.log(stableString); // Output: '{\"b\":1,\"a\":2}'"}

Custom Replacer

This feature allows you to provide a custom replacer function to filter or modify values during the stringification process. In this example, the key 'b' is excluded from the resulting JSON string.

{"typescript":"import stringify from 'json-stable-stringify';\n\nconst obj = { b: 1, a: 2, c: 3 };\nconst stableString = stringify(obj, { replacer: (key, value) => key === 'b' ? undefined : value });\nconsole.log(stableString); // Output: '{\"a\":2,\"c\":3}'"}

Other packages similar to @types/json-stable-stringify

FAQs

Package last updated on 28 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts